import Dysmsapi20170525 from '@alicloud/dysmsapi20170525';
import { Config } from '@alicloud/openapi-client'
import { RuntimeOptions } from '@alicloud/tea-util';
import { DependencyContainer } from 'tsyringe';
import { ROOT } from '@sker/core';
import { join } from 'path';
export interface SmsHandler<T> {
    (sms: Dysmsapi20170525, runtime: RuntimeOptions): Promise<T>
}
export const useSms = async <T>(injector: DependencyContainer, handler: SmsHandler<T>) => {
    const root = injector.resolve(ROOT)
    const jsonFile = join(`${root}`, 'data/plugins', `@sker/sms.json`)
    const jsonConfig = require(jsonFile)
    let config = new Config({
        // 必填，您的 AccessKey ID
        accessKeyId: jsonConfig.accessKeyId,
        // 必填，您的 AccessKey Secret
        accessKeySecret: jsonConfig.accessKeySecret,
    });
    // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
    config.endpoint = jsonConfig.endpoint || `dysmsapi.aliyuncs.com`;
    const dysmsApi = new Dysmsapi20170525(config);
    const options = new RuntimeOptions({})
    const result = await handler(dysmsApi, options)
    return result;
}